<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户id" prop="businessId">
        <el-input
          v-model="queryParams.businessId"
          placeholder="请输入商户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="收入明细" name="first">
        <el-table v-loading="loading" :data="suanList" @selection-change="handleSelectionChange">
          <el-table-column label="公寓名称" align="center" prop="totalSum" />
        </el-table>
        <span>押金总计：</span><span>租金总计：</span><span>电费总计：</span><span>水费总计：</span><span>宽带总计：</span>
        <span>燃气费总计：</span><span>有线电视总计：</span><span>其他总计：</span>
        <el-table v-loading="loading" :data="dayList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="公寓名称" align="center" prop="businessName" />
          <el-table-column label="交易时间" align="center" prop="dealDate" />
          <el-table-column label="总计" align="center" prop="total" />
          <el-table-column label="押金" align="center" prop="deposit" />
          <el-table-column label="租金" align="center" prop="rent" />
          <el-table-column label="电费" align="center" prop="electricityFee" />
          <el-table-column label="水费" align="center" prop="waterFee" />
          <el-table-column label="宽带费" align="center" prop="netFee" />
          <el-table-column label="燃气费" align="center" prop="gasFee" />
          <el-table-column label="有线电视费" align="center" prop="cableFee" />
          <el-table-column label="其他" align="center" prop="otherFee" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </el-tab-pane>
      <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
    </el-tabs>



    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户id" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户id" />
        </el-form-item>
        <el-form-item label="商户名称" prop="businessName">
          <el-input v-model="form.businessName" placeholder="请输入商户名称" />
        </el-form-item>
        <el-form-item label="1：线上无金融属性的  2：线上有金融属性的(如：租约保理) 3：线下(商户既有线上1，也有线下3，海链财务只有线上1,2) " prop="onlineFlg">
          <el-input v-model="form.onlineFlg" placeholder="请输入1：线上无金融属性的  2：线上有金融属性的(如：租约保理) 3：线下(商户既有线上1，也有线下3，海链财务只有线上1,2) " />
        </el-form-item>
        <el-form-item label="统计日期(交易日期)" prop="dealDate">
          <el-date-picker clearable size="small"
            v-model="form.dealDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择统计日期(交易日期)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="操作类型,1：收入，2：支出" prop="operationType">
          <el-select v-model="form.operationType" placeholder="请选择操作类型,1：收入，2：支出">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="总计" prop="total">
          <el-input v-model="form.total" placeholder="请输入总计" />
        </el-form-item>
        <el-form-item label="押金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入押金" />
        </el-form-item>
        <el-form-item label="租金" prop="rent">
          <el-input v-model="form.rent" placeholder="请输入租金" />
        </el-form-item>
        <el-form-item label="电费" prop="electricityFee">
          <el-input v-model="form.electricityFee" placeholder="请输入电费" />
        </el-form-item>
        <el-form-item label="水费" prop="waterFee">
          <el-input v-model="form.waterFee" placeholder="请输入水费" />
        </el-form-item>
        <el-form-item label="宽带费" prop="netFee">
          <el-input v-model="form.netFee" placeholder="请输入宽带费" />
        </el-form-item>
        <el-form-item label="燃气费" prop="gasFee">
          <el-input v-model="form.gasFee" placeholder="请输入燃气费" />
        </el-form-item>
        <el-form-item label="有线电视费" prop="cableFee">
          <el-input v-model="form.cableFee" placeholder="请输入有线电视费" />
        </el-form-item>
        <el-form-item label="商户充值金额(在海链财务报表中算作收入的一部分）" prop="czFee">
          <el-input v-model="form.czFee" placeholder="请输入商户充值金额(在海链财务报表中算作收入的一部分）" />
        </el-form-item>
        <el-form-item label="其他" prop="otherFee">
          <el-input v-model="form.otherFee" placeholder="请输入其他" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识：0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识：0:未删除，1：删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFind,listSuan,listDay, getDay, delDay, addDay, updateDay } from "@/api/finance/deal";

export default {
  name: "Day",
  components: {
  },
  data() {
    return {
      activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dayList: [],
      suanList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        totalSum:null,
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getSuan();
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getSuan() {
      this.loading = true;
      listSuan(this.queryParams).then(response => {
        console.log(response.totalSum)
        this.listSuan = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listFind(this.queryParams).then(response => {
        this.dayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDay(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDay(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDay(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDay(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/deal/export', {
        ...this.queryParams
      }, `system_day.xlsx`)
    }
  }
};
</script>
